package com.test.action;

import java.awt.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8202009251833049119L;

	private String username;

	private String password;

	private String repassword;

	private int age;

	private Date birthday;

	private Date graduation;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Date getGraduation() {
		return graduation;
	}

	public void setGraduation(Date graduation) {
		this.graduation = graduation;
	}

	@Override
	public String execute() throws Exception {

		return SUCCESS;// validateExecute()
	}

	public String test() throws Exception {

		return SUCCESS;
	}

	/*
	 * public String abc() throws Exception{
	 * System.out.println("abc~~~~~~~~~~~~"); return SUCCESS; }
	 * 
	 * public void validateAbc(){
	 * 
	 * System.out.println("validateAbc() invoke"); }
	 */

	@Override
	public void validate() {

		System.out.println("~~~~~~~~~~~~");

		// this.getFieldErrors().put("username", "bbbbbbbbbbbbbbbbbb");
		//		
		// if (null == username || username.length() < 6 || username.length() >
		// 10) {
		//		
		// this.addActionError("username should not be blank!");
		// }
		//		
		// if (null == password || password.length() < 6 || password.length() >
		// 10) {
		//		
		// this.addActionError("password is invalid");
		// } else if (null == repassword || repassword.length() < 6
		// || repassword.length() > 10) {
		// this.addActionError("re-password is invalid");
		//		
		// } else if (!password.equals(repassword)) {
		// this.addActionError("two passwords are not the same!");
		// }
		//		
		//				
		// if (age <= 0 || age > 150) {
		// this.addActionError("age is invalid");
		// }
		//
		// if (null != birthday && null != graduation) {
		//		
		// Calendar c1 = Calendar.getInstance();
		// c1.setTime(birthday);
		//		
		// Calendar c2 = Calendar.getInstance();
		// c2.setTime(graduation);
		//		
		// if (!c1.before(c2)) {
		//		
		// this.addActionError("生日应该小于毕业时间!");
		// }
		// }

		if (null == username || username.length() < 6 || username.length() > 10) {

			ArrayList list = new ArrayList();

			list.add(username);

			this.addActionError(this.getText("username.invalid", new String[]{username}));
		}

		// if (null == password || password.length() < 6 || password.length() >
		// 10) {
		//
		// this.addFieldError("password", "password is invalid");
		// } else if (null == repassword || repassword.length() < 6
		// || repassword.length() > 10) {
		// this.addFieldError("repassword", "re-password is invalid");
		//
		// } else if (!password.equals(repassword)) {
		// this.addFieldError("password", "two passwords are not the same!");
		// }
		//
		//		
		// if (age < 0 || age > 150) {
		// this.addFieldError("age", "age is invalid");
		// }
		// // if (age < 1 || age > 150) {
		// // this.addFieldError("age", "age is invalid");
		// // }
		// // if (null == birthday) {
		// // this.addFieldError("birthday", "birthday invalid");
		// // }
		// // if (null == graduation) {
		// //
		// // this.addFieldError("graduation", "graduation invalid");
		// // }
		// if (null != birthday && null != graduation) {
		//
		// Calendar c1 = Calendar.getInstance();
		// c1.setTime(birthday);
		//
		// Calendar c2 = Calendar.getInstance();
		// c2.setTime(graduation);
		//
		// if (!c1.before(c2)) {
		//
		// this.addFieldError("birthday",
		// "birthday should be before the graduation");
		// }
		// }
	}

}
